/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.game.state;

import deatax.game.display.CameraController;
import deatax.game.model.controller.ModelController;
import deatax.game.model.importer.PMMLoader;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;

/**
 *
 * @author pson
 */
public class TestGameState extends GameState {

    private CameraController cam;
    private ModelController model;
    
    public TestGameState() {
        super("test");
        try {
        model = new ModelController(PMMLoader.loadModel(new BufferedInputStream(new FileInputStream("WusonOBJ.pmm"))));
        } catch (IOException ex) {
        }
        cam = new CameraController();
        
    }
    
    @Override
    public void init(GL2 gl) {
        cam.init(gl);
        model.init(gl);
    }

    @Override
    public void update(long time) {
        cam.update(time);
    }

    @Override
    public void draw(GL2 gl, long time) {
        gl.glClearColor(0.1f, 0.9f, 0.9f, 1.0f);
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        //GLU glu = GLU.createGLU();
        //glu.gluLookAt(0, 10, 10, 0, 0, 0, 0, 1, 0);
        cam.project(gl);
        drawGrid(gl);
        model.draw(gl, time);
    }
    
    private void drawGrid(GL2 gl) {
        gl.glColor3f(0f, 0f, 0f);

        gl.glBegin(GL.GL_LINE_LOOP);
        gl.glVertex2i(100, 0);
        gl.glVertex2i(-100, 0);
        gl.glEnd();

        gl.glBegin(GL.GL_LINE_LOOP);
        gl.glVertex2i(0, 100);
        gl.glVertex2i(0, -100);
        gl.glEnd();

        gl.glBegin(GL.GL_LINE_LOOP);
        gl.glVertex3i(0, 0, 100);
        gl.glVertex3i(0, 0, -100);
        gl.glEnd();
    }

}
